package com.i2works.smartluolong.utils.basecommon;

import com.i2works.smartluolong.utils.common.DateUtils;
import com.xiaoleilu.hutool.date.DateUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Date;

/**
 * 公共控制器
 *
 * @author Liu Yutao <koal@vip.qq.com>
 * @date 2018/1/16 17:10
 */

public class BaseCommonController extends BaseUploadController {

    protected final Logger logger = LoggerFactory.getLogger(getClass());


    /**
     * 是否老年人（满60岁，匹配年月日，差一天过生日，即不满60岁）
     * fixme 暂时写30，便于测试，正式环境改成60
     */
    public static boolean isOlder_60(String birthday) {
        Date date = DateUtils.str2Date(birthday, "yyyyMMdd");
        long betweenYear = DateUtil.betweenYear(date, new Date(), false);
        return betweenYear >= 20;
    }
    

    /**
     * 是否老年人（满70岁，匹配年月日，差一天过生日，即不满70岁）
     * fixme 暂时写30，便于测试，正式环境改成70
     */
    public static boolean isOlder_70(String birthday) {
        Date date = DateUtils.str2Date(birthday, "yyyyMMdd");
        long betweenYear = DateUtil.betweenYear(date, new Date(), false);
        return betweenYear >= 70;
    }

    /**
     * 是否成年人（满足结婚年龄男22，女20）
     */
    public static boolean isAdult(String birthday, String sex) {
        Date date = DateUtils.str2Date(birthday, "yyyyMMdd");
        long betweenYear = DateUtil.betweenYear(date, new Date(), false);
        if ("男".equals(sex)) {
            return betweenYear >= 22;
        } else {
            return betweenYear >= 20;
        }
    }



}
